package com.beiding.workordersystem.orders.common.controller;

import com.beiding.workordersystem.common.standard.R;
import com.beiding.workordersystem.orders.common.service.CommissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/commission")
public class CommissionController {

    @Autowired
    private CommissionService service;

    @GetMapping("/user/list")
    R list(Date start, Date to) {
        return R.ok(service.list(start, to));
    }

    @GetMapping("/satrap/list")
    R satrap(Date start, Date to) {
        return R.ok(service.satrapList(start, to));
    }

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }

}
